Skip to content

Remove C-wrapper for MPI_Waitall #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2025
Merged

Conversation

adit4443ya
Copy link
Collaborator

No description provided.

src/mpi.f90 Outdated
! Allocate temporary arrays for the C representations.
type(c_ptr), allocatable :: c_requests(:)
type(c_ptr), allocatable :: c_statuses(:)
allocate(c_requests(count))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lfortran treats arrays of type(c_ptr) as scalar

No specific test file given. Will compile/run all .f90 tests...
semantic error: Array reference is not allowed on scalar variable
   --> ../src/mpi.f90:688:13
    |
688 |             c_requests(i) = c_mpi_request_f2c(array_of_requests(i))
    |             ^^^^^^^^^^^^^ 


Note: Please report unclear, confusing or incorrect messages as bugs at
https://github.com/lfortran/lfortran/issues.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just make it a non-allocatable by doing type(c_ptr) :: c_requests(count), would that be ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope it too gives error

 aditya-trivedi   tests    wait_2 ≢  ~1    gfortran -c test.f90 
 aditya-trivedi   tests    wait_2 ≢  ?1 ~1    lfortran -c test.f90 
semantic error: Array reference is not allowed on scalar variable
 --> test.f90:6:5
  |
6 |     a(1) = c_loc(i)
  |     ^^^^ 


Note: Please report unclear, confusing or incorrect messages as bugs at
https://github.com/lfortran/lfortran/issues.
 aditya-trivedi   tests    wait_2 ≢  ?1 ~1    cat test.f90 
program main
    use iso_c_binding, only: c_ptr, c_loc
    type(c_ptr) :: a(10)
    integer ,target:: i=1
    ! allocate(a(10))
    a(1) = c_loc(i)
end program

Here is small mre which i tried

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. We've an error with GFortran + MPICH as well for both standalone test and POT3D as well, so there is something wrong with the Fortran code either in mpi.f90 or mpi_c_bindings.f90, I think we should try to fix that first.

Then we would've a better understanding of whether something is actually needed to be fixed in LFortran or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem we discovered in LFortran, probably is fixed with the PR: lfortran/lfortran#6839.

Copy link
Collaborator

@gxyd gxyd Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, I still don't know exactly why this PR (to remove the C wrapper) doesn't work with MPICH but works with Open MPI.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please fix LFortran for all bugs. That's why we are doing it also. :)

That PR is merged, so this might fix it --- can you try locally?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still get an error, I'm extracting the MRE for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other error albeit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is an LFortran error, then extract it and fix it. That's a very valuable thing to do.

@adit4443ya
Copy link
Collaborator Author

Now all GFortran tests passes (especially with MPICH) thanks to @gxyd for #99

@adit4443ya
Copy link
Collaborator Author

adit4443ya commented Apr 10, 2025

Now there is new llvm error

declare void @_lpython_free_argv()
asr_to_llvm: module failed verification. Error:
Call parameter type does not match function signature!
  %25 = getelementptr inbounds i32, ptr %array_of_requests, i32 %23
 i32  %26 = call i32 @MPI_Request_f2c(ptr %25)
Call parameter type does not match function signature!
  %49 = getelementptr inbounds i32, ptr %4, i32 %47
 i32  %50 = call i32 @MPI_Request_c2f(ptr %49)

I'm extracting MRE for it

@adit4443ya
Copy link
Collaborator Author

opened in here lfortran/lfortran#6951

@gxyd
Copy link
Collaborator

gxyd commented Apr 10, 2025

We've an approval from @certik , I'll merge this PR.

And instead of necessarily needing to fix the issue: lfortran/lfortran#6951, we've used a simple workaround for now.

I'm merging this PR now.

@adit4443ya adit4443ya merged commit 683a051 into lfortran:main Apr 10, 2025
20 checks passed
@adit4443ya
Copy link
Collaborator Author

I merged it!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants